Fix documenting binaries with libraries
authorAlex Crichton <alex@alexcrichton.com>
Mon, 23 Mar 2015 05:01:55 +0000 (22:01 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 23 Mar 2015 05:01:55 +0000 (22:01 -0700)
src/cargo/ops/cargo_rustc/context.rs
tests/test_cargo_compile_plugins.rs

index 70ccd88ffdf6a65d8649f1d30f3f717dcc9597f4..87e1092e3ca7b9626e300dbafc4cf61bfdaf4184 100644 (file)
@@ -330,7 +330,7 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
                        profile: &Profile)
                        -> Vec<(&'a Package, &'a Target, &'a Profile)> {
         if profile.doc {
-            return self.doc_deps(pkg);
+            return self.doc_deps(pkg, target);
         }
         let deps = match self.resolve.deps(pkg.package_id()) {
             None => return Vec::new(),
@@ -386,8 +386,9 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
     }
 
     /// Returns the dependencies necessary to document a package
-    fn doc_deps(&self, pkg: &Package)
+    fn doc_deps(&self, pkg: &Package, target: &Target)
                 -> Vec<(&'a Package, &'a Target, &'a Profile)> {
+        let pkg = self.get_package(pkg.package_id());
         let deps = self.resolve.deps(pkg.package_id()).into_iter();
         let deps = deps.flat_map(|a| a).map(|id| {
             self.get_package(id)
@@ -411,11 +412,16 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
         }
 
         // Be sure to build/run the build script for documented libraries as
-        // well
-        let pkg = self.get_package(pkg.package_id());
         if let Some(t) = pkg.targets().iter().find(|t| t.is_custom_build()) {
             ret.push((pkg, t, self.build_script_profile(pkg.package_id())));
         }
+
+        // If we document a binary, we need the library available
+        if target.is_bin() {
+            if let Some(t) = pkg.targets().iter().find(|t| t.is_lib()) {
+                ret.push((pkg, t, self.lib_profile(pkg.package_id())));
+            }
+        }
         return ret
     }
 
index b983e2cfbdc33d5d802558d3cfa53da1dcd67b7c..798c6ca6f8cd18df66eb6890442c62e5f59def54 100644 (file)
@@ -49,7 +49,7 @@ test!(plugin_to_the_max {
             path = "../baz"
         "#)
         .file("src/lib.rs", r#"
-            #![feature(plugin_registrar)]
+            #![feature(plugin_registrar, rustc_private)]
 
             extern crate rustc;
             extern crate baz;
@@ -57,7 +57,7 @@ test!(plugin_to_the_max {
             use rustc::plugin::Registry;
 
             #[plugin_registrar]
-            pub fn foo(reg: &mut Registry) {
+            pub fn foo(_reg: &mut Registry) {
                 println!("{}", baz::baz());
             }
         "#);